﻿namespace NorthernLights.Core
{
    using System;

    /// <summary>
    /// ByteGenerator class.
    /// </summary>
    public class ByteGenerator
    {
        #region Fields
        private static Random random = new Random();
        #endregion

        #region Methods
        /// <summary>
        /// Generates a byte array with random numbers.
        /// </summary>
        /// <param name="size">The desired size for the byte array.</param>
        /// <returns>A byte array with random numbers of specified size.</returns>
        public static byte[] Generate(int size)
        {
            byte[] result = new byte[size];

            random.NextBytes(result);

            return result;
        }

        /// <summary>
        /// Compare the content of two byte arrays.
        /// </summary>
        /// <param name="one">First byte array.</param>
        /// <param name="two">Second byte array.</param>
        /// <returns>Return true if the byte arrays have the same content.</returns>
        public static bool HaveSameContent(byte[] one, byte[] two)
        {
            if (one == null & two == null)
            {
                return true;
            }

            if ((one == null && two != null) || (one != null && two == null))
            {
                return false;
            }

            if (one.Length != two.Length)
            {
                return false;
            }

            bool different = false;

            for (int i = 0; i < one.Length; i++)
            {
                if (one[i] != two[i])
                {
                    different = true;
                    break;
                }
            }

            return !different;
        }
        #endregion
    }
}
